package me.spring.cloud.common.components.util.enums;


import me.spring.cloud.common.components.util.enums.inter.EnumLeab;
import me.spring.cloud.common.components.util.enums.inter.RegularEnum;
import java.util.regex.Pattern;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @description: 日期类型
 * @author: luffy
 * @create: 2018-07-20 16:12
 **/

@Getter
@AllArgsConstructor
public enum DateTypeEnum implements RegularEnum<String>, EnumLeab<String> {
  YYYY("(?!0000)[0-9]{4}", "年"),
  YYYYMM("^(?:(?!0000)[0-9]{4}([-/.]?)(?:(?:0?[1-9]|1[0-2])))$", "年月"),
  YYYYMMDD(
      "^(?:(?!0000)[0-9]{4}([-/.]?)(?:(?:0?[1-9]|1[0-2])([-/.]?)(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])([-/.]?)(?:29|30)|(?:0?[13578]|1[02])([-/.]?)31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2([-/.]?)29)$",
      "年月日"),
  YYYYMMDDHHMMSS(
      "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)\\s+([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$",
      "年月日时分秒");
  private String regular;
  private String leab;

  public boolean matches(String string) {
    Pattern pattern = Pattern.compile(this.regular);
    return pattern.matcher(string).matches();
  }
}
